package cn.tedu.service.impl;

import cn.tedu.entity.Log;
import cn.tedu.mapper.LogMapper;
import cn.tedu.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service //声明service层,交给Spring容器管理
public class LogServiceImpl implements LogService {
    @Autowired
    private LogMapper logMapper;


    @Async
    //@Transactional(propagation = Propagation.REQUIRED)
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Override
    public void insert(Log log) {
        System.out.println(Thread.currentThread().getName()+"-->LogServiceImpl.insert");
        try{Thread.sleep(5000);}catch (Exception e){} //模拟写的耗时操作
        System.out.println(log);
        logMapper.insert(log);
    }
}
